package com.ruoyi.project.system.goods.follow.controller;

import java.util.List;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import com.ruoyi.framework.aspectj.lang.annotation.Log;
import com.ruoyi.framework.aspectj.lang.enums.BusinessType;
import com.ruoyi.project.system.goods.follow.domain.GoodsFollow;
import com.ruoyi.project.system.goods.follow.service.IGoodsFollowService;
import com.ruoyi.framework.web.controller.BaseController;
import com.ruoyi.framework.web.domain.AjaxResult;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.framework.web.page.TableDataInfo;

/**
 * 产品关注Controller
 * 
 * @author f_baisi
 * @date 2020-06-26
 */
@Controller
@RequestMapping("/system/follow")
public class GoodsFollowController extends BaseController
{
    private String prefix = "system/follow";

    @Autowired
    private IGoodsFollowService goodsFollowService;

    @RequiresPermissions("system:follow:view")
    @GetMapping()
    public String follow()
    {
        return prefix + "/follow";
    }

    /**
     * 查询产品关注列表
     */
    @RequiresPermissions("system:follow:list")
    @PostMapping("/list")
    @ResponseBody
    public TableDataInfo list(GoodsFollow goodsFollow)
    {
        startPage();
        List<GoodsFollow> list = goodsFollowService.selectGoodsFollowList(goodsFollow);
        return getDataTable(list);
    }

    /**
     * 导出产品关注列表
     */
    @RequiresPermissions("system:follow:export")
    @Log(title = "产品关注", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    @ResponseBody
    public AjaxResult export(GoodsFollow goodsFollow)
    {
        List<GoodsFollow> list = goodsFollowService.selectGoodsFollowList(goodsFollow);
        ExcelUtil<GoodsFollow> util = new ExcelUtil<GoodsFollow>(GoodsFollow.class);
        return util.exportExcel(list, "follow");
    }

    /**
     * 新增产品关注
     */
    @GetMapping("/add")
    public String add()
    {
        return prefix + "/add";
    }

    /**
     * 新增保存产品关注
     */
    @RequiresPermissions("system:follow:add")
    @Log(title = "产品关注", businessType = BusinessType.INSERT)
    @PostMapping("/add")
    @ResponseBody
    public AjaxResult addSave(GoodsFollow goodsFollow)
    {
        return toAjax(goodsFollowService.insertGoodsFollow(goodsFollow));
    }

    /**
     * 修改产品关注
     */
    @GetMapping("/edit/{id}")
    public String edit(@PathVariable("id") String id, ModelMap mmap)
    {
        GoodsFollow goodsFollow = goodsFollowService.selectGoodsFollowById(id);
        mmap.put("goodsFollow", goodsFollow);
        return prefix + "/edit";
    }

    /**
     * 修改保存产品关注
     */
    @RequiresPermissions("system:follow:edit")
    @Log(title = "产品关注", businessType = BusinessType.UPDATE)
    @PostMapping("/edit")
    @ResponseBody
    public AjaxResult editSave(GoodsFollow goodsFollow)
    {
        return toAjax(goodsFollowService.updateGoodsFollow(goodsFollow));
    }

    /**
     * 删除产品关注
     */
    @RequiresPermissions("system:follow:remove")
    @Log(title = "产品关注", businessType = BusinessType.DELETE)
    @PostMapping( "/remove")
    @ResponseBody
    public AjaxResult remove(String ids)
    {
        return toAjax(goodsFollowService.deleteGoodsFollowByIds(ids));
    }
}
